/// 能量平衡数据模型
class EnergyBalance {
  final int? energyBalance; // 能量平衡
  final int? totalFoodKcal; // 总饮食摄入
  final int? proteinKcal; // 蛋白质卡路里
  final int? carbohydrateKcal; // 碳水化合物卡路里
  final int? fatKcal; // 脂肪卡路里
  final int? totalExerciseKcal; // 总消耗
  final int? basalMetabolism; // 基础代谢
  final int? sportKcal; // 运动消耗
  final int? dailyKcal; // 日常活动

  const EnergyBalance({
    this.energyBalance,
    this.totalFoodKcal,
    this.proteinKcal,
    this.carbohydrateKcal,
    this.fatKcal,
    this.totalExerciseKcal,
    this.basalMetabolism,
    this.sportKcal,
    this.dailyKcal,
  });

  factory EnergyBalance.fromMap(Map<String, dynamic> map) {
    return EnergyBalance(
      energyBalance: map['energyBalance'] as int?,
      totalFoodKcal: map['totalFoodKcal'] as int?,
      proteinKcal: map['proteinKcal'] as int?,
      carbohydrateKcal: map['carbohydrateKcal'] as int?,
      fatKcal: map['fatKcal'] as int?,
      totalExerciseKcal: map['totalExerciseKcal'] as int?,
      basalMetabolism: map['basalMetabolism'] as int?,
      sportKcal: map['sportKcal'] as int?,
      dailyKcal: map['dailyKcal'] as int?,
    );
  }

  /// 获取能量平衡状态文本
  String getBalanceStatusText() {
    if (energyBalance == null) return '达成减重';
    if (energyBalance! < 0) return '达成减重';
    return '达成增肌';
  }

  /// 计算进度条位置 (-1000 到 1000 的范围映射到 0.0 到 1.0)
  double getProgressValue() {
    if (energyBalance == null) return 0.5;
    // 将 -1000 到 1000 映射到 0.0 到 1.0
    final value = (energyBalance! + 1000) / 2000;
    return value.clamp(0.0, 1.0);
  }
}
